package com.laundry.service.impl;

import com.laundry.dao.ClothesTypeDao;
import com.laundry.entity.ClothesType;
import com.laundry.service.ClothesTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class ClothesTypeServiceImpl implements ClothesTypeService {

    @Autowired
    private ClothesTypeDao clothesTypeDao;
    
    @Override
    public List<ClothesType> findAll() {
        return clothesTypeDao.findAll();
    }
    
    @Override
    public ClothesType findById(Long id) {
        return clothesTypeDao.findById(id).orElse(null);
    }
    
    @Override
    public ClothesType save(ClothesType clothesType) {
        clothesType.setCreateTime(new Date());
        clothesType.setUpdateTime(new Date());
        return clothesTypeDao.save(clothesType);
    }
    
    @Override
    public ClothesType update(ClothesType clothesType) {
        ClothesType existClothesType = clothesTypeDao.findById(clothesType.getId()).orElse(null);
        if (existClothesType == null) {
            return null;
        }
        
        clothesType.setCreateTime(existClothesType.getCreateTime());
        clothesType.setUpdateTime(new Date());
        return clothesTypeDao.save(clothesType);
    }
    
    @Override
    public void deleteById(Long id) {
        clothesTypeDao.deleteById(id);
    }
} 